package com.lbd.system.controller;

import com.lbd.system.bean.UserAuthentication;
import com.lbd.system.service.UserAuthenticationService;
import com.lbd.base.controller.BaseController;
import com.lbd.commons.Result;
import com.lbd.commons.ResultState;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/userauthentication")
public class UserAuthenticationController extends BaseController {
    private final Logger log = Logger.getLogger(this.getClass());

    @Autowired
    private UserAuthenticationService userauthenticationService;

    /**
     * 按条件分页查询userauthentication
     *
     * @param page               第几页
     * @param rows               一页多少条
     * @param userauthentication
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public Result list(int page, int rows, UserAuthentication userauthentication) {
        return new Result(ResultState.SUCCESS, "查询成功", userauthenticationService.findByPageConditionJpql(page, rows, userauthentication));
    }

    /**
     * 保存userauthentication信息
     *
     * @param userauthentication
     * @return
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Result save(UserAuthentication userauthentication) {
        userauthenticationService.save(userauthentication);
        return new Result(ResultState.SUCCESS, "添加成功", "");
    }

    /**
     * 根据id查询回显要编辑的UserAuthentication
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/edit", method = RequestMethod.GET)
    public Result toEdit(String id) {
        return new Result(ResultState.SUCCESS, "加载成功", userauthenticationService.findById(id));
    }

    /**
     * 修改userauthentication信息
     *
     * @param userauthentication
     * @return
     */
    @RequestMapping(value = "/edit", method = RequestMethod.POST)
    public Result update(UserAuthentication userauthentication) {
        userauthenticationService.update(userauthentication);
        return new Result(ResultState.SUCCESS, "更新成功");
    }


}
